package com.meixiang.adapter.personalCenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.entity.servicOrder.AllServiceOrderResult;

import butterknife.Bind;
import butterknife.ButterKnife;


public class AllAppointmentItemAdapter extends RecyclerView.Adapter<AllAppointmentItemAdapter.ViewHolder> {


    private Context context;
    private int position;
    private String status ;
    private AllServiceOrderResult allServiceOrder ;

    public AllAppointmentItemAdapter(Context context,String status){
        this.context = context ;
        this.status = status ;
    }
    public AllAppointmentItemAdapter(Context context, AllServiceOrderResult allServiceOrder , String status){
        this.context = context ;
        this.status = status ;
        this.position = allServiceOrder.getList().size();
        this.allServiceOrder = allServiceOrder ;
    }

    public AllAppointmentItemAdapter(Context context) {
        this.context = context;
        this.position = allServiceOrder.getList().size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.activity_all_appointment_custom_list_items, null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    /**
     * @param holder
     * @param position
     */

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        if (this.position - 1!= position) {
            holder.viewLine.setVisibility(View.VISIBLE);
        } else {
            holder.viewLine.setVisibility(View.GONE);
        }

        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickListener.onItemClick(holder.itemView, pos);

                }
            });
        }

    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    @Override
    public int getItemCount() {
        return allServiceOrder.getList().size();
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.all_appointment_item_iv)
        ImageView all_appointment_item_iv ;
        @Bind(R.id.all_appointment_item_tv_detail)
        TextView all_appointment_item_tv_detail ;
        @Bind(R.id.all_appointment_item_tv_keyword)
        TextView all_appointment_item_tv_keyword ;
        @Bind(R.id.all_appointment_item_view_line)
        View viewLine ;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
